package com.bonc.rms.service.tms.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bonc.rms.jpa.tms.TalentRepository;
import com.bonc.rms.service.tms.IEmployeeService;

@Service(value = "employeeService")
public class EmployeeService implements IEmployeeService {
	@Autowired
	private TalentRepository talentRepository;

	public List<String> getAgeDistribute(Integer departmentId) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		sdf.format(date);
		List<String> list = new ArrayList<>();
		if (departmentId.equals(null)&departmentId.equals("")) {
			int age1 = talentRepository.getAllByDate(sdf, 0, 1);
			list.add("name:'一年以内',vale=" + age1);
			int age2 = talentRepository.getAllByDate(sdf, 1, 3);
			list.add("name:'一到三年',vale=" + age2);
			int age3 = talentRepository.getAllByDate(sdf, 3, 5);
			list.add("name:'三到五年',vale=" + age3);
			int age4 = talentRepository.getAllByDate(sdf, 5, 10);
			list.add("name:'五到十年',vale=" + age4);
			int age5 = talentRepository.getAllByDate(sdf, 10, 200);
			list.add("name:'十年以上',vale=" + age5);

		} else {
			int age1 = talentRepository.getAllByDateGroupByDepartmentId(sdf, 0,
					1, departmentId);
			list.add("name:'一年以内',vale=" + age1);
			int age2 = talentRepository.getAllByDateGroupByDepartmentId(sdf, 1,
					3, departmentId);
			list.add("name:'一到三年',vale=" + age2);
			int age3 = talentRepository.getAllByDateGroupByDepartmentId(sdf, 3,
					5, departmentId);
			list.add("name:'三到五年',vale=" + age3);
			int age4 = talentRepository.getAllByDateGroupByDepartmentId(sdf, 5,
					10, departmentId);
			list.add("name:'五到十年',vale=" + age4);
			int age5 = talentRepository.getAllByDateGroupByDepartmentId(sdf,
					10, 200, departmentId);
			list.add("name:'十年以上',vale=" + age5);
		}
		return list;
	}

}
